package com.hou.apizuul;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.stereotype.Component;

//Zuul过滤器
@Component
public class ErrorZuulFilter extends ZuulFilter {

    @Override
    public String filterType() {
        return "error";
    }
    @Override
    public int filterOrder() {
        return 1;
    }
    @Override
    public boolean shouldFilter() {
        return true;
    }
    @Override
    public Object run() throws ZuulException {
        RequestContext currentContext = RequestContext.getCurrentContext();
        Throwable throwable = currentContext.getThrowable();
        //记录异常信息
        String message = throwable.getCause().getMessage();
        System.out.println("error:"+message);
        return null;
    }
}
